<template>
	<view class="wrap-item flex align-center just-between row-item" v-if="item">
		<view class="title-bg f-30 flex">
			<view class="must" v-if="item.require">*</view>

			<view class="title">{{ item.title }}</view>
		</view>

		<view class="wrap-right flex align-center just-end">
			<input
				class="input f-30 text-right"
				:placeholder="item.place"
				placeholder-class="place"
				:value="value"
				@input="$emit('input', $event.detail.value)"
				:type="item.mode"
				:maxlength="item.maxlength"
			/>

			<image class="camera" :src="$staticImagePath('mine/authen_orc.png')" @click="onCamera" />
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			/**
			 * 输入框的值
			 */
			value: {
				type: String,
				default: "",
			},
			/**
			 * 数据
			 */
			item: {
				type: Object,
				default: null,
			},
			/**
			 * 识别的类型
			 */
			ocrType: {
				type: String,
				default: "IdCard",
			},
		},
		methods: {
			/**
			 * 点击识别
			 */
			onCamera() {
				this.$filters.onChooseImage(1, (res) => {
					this.onUpload(res[0]);
				});
			},
			/**
			 * 上传图片
			 */
			onUpload(file) {
				this.$commonNetwork.onUploadFile(file, (res) => {
					this.onOcrData(res.url);
				});
			},
			/**
			 * 识别
			 */
			onOcrData(url) {
				this.$commonNetwork.onDistinguishOCRData(url, this.ocrType, (res) => {
					this.$emit("ocrData", res);
				});
			},
		},
	};
</script>

<style>
	@import "@/css/publish.css";
</style>
